home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / GraphicObject.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  6.9 KB  |  325 lines

  1. /* ==========================================================================
  2. **
  3. **                          GraphicObject.c
  4. **
  5. **   ©1991 WILLISoft
  6. **
  7. ** ==========================================================================
  8. */
  9. #include "GraphicObject.h"
  10. #include "GraphicObjectClass.h"
  11.  
  12. void
  13. GraphicObject_CleanUp( GraphicObject *self )
  14. {
  15.    SetTitle( self, NULL );
  16. }
  17.  
  18.  
  19. BOOL GraphicObject_elaborated = FALSE;
  20.  
  21. struct GraphicObjectClass GraphicObject_Class;
  22.  
  23. void GraphicObjectClass_Init( struct GraphicObjectClass *class )
  24. {
  25.    PObjectClass_Init( (struct PObjectClass *) class );
  26.    class->isa            = PObjectClass();
  27.    class->ClassName      = "GraphicObject";
  28.    class->CleanUp        = (void(*)(PObject *))GraphicObject_CleanUp;
  29.    class->Location       = NULL;
  30.    class->SetLocation    = NULL;
  31.    class->Size           = NULL;
  32.    class->AskSize        = NULL;
  33.    class->SetSize        = NULL;
  34.    class->SizeFlags      = GraphicObject_SizeFlagsAll;
  35.                            /* default to sizeable on both axis. */
  36.    class->Render           = NULL;
  37.    class->SetTitle         = NULL;
  38.    class->Title            = NULL;
  39.  
  40. /* additions for font information */
  41.    class->DefaultFont      = NULL;
  42.    class->SetDefaultFont   = NULL;
  43.  
  44.    class->BuilderMethods   = NULL;
  45.    class->TextAlignment    = NULL;
  46.    class->SetTextAlignment = NULL;
  47.  
  48. }
  49.  
  50.  
  51. struct GraphicObjectClass *GraphicObjectClass( void )
  52. {
  53.    if( ! GraphicObject_elaborated )
  54.    {
  55.       GraphicObjectClass_Init( &GraphicObject_Class );
  56.       GraphicObject_elaborated = TRUE;
  57.    }
  58.  
  59.    return &GraphicObject_Class;
  60. }
  61.  
  62.  
  63.  
  64. Point Point_ZeroZero = {0,0};
  65.  
  66.  
  67. Point Location( GraphicObject *self )
  68. /* Returns the LeftEdge, TopEdge of 'self'. */
  69. {
  70.    Point                     pos;
  71.    struct GraphicObjectClass *class;
  72.  
  73.    pos = Point_ZeroZero;
  74.  
  75.    if( class = (struct GraphicObjectClass *)self->isa )
  76.    {
  77.       if( class->Location )
  78.          pos = (*class->Location)( self );
  79.    }
  80.    return pos;
  81. }
  82.  
  83.  
  84. Point SetLocation( GraphicObject *self,
  85.                    PIXELS         LeftEdge,
  86.                    PIXELS         TopEdge )
  87. /* Sets the LeftEdge, TopEdge of 'self'.
  88.  * Returns the LeftEdge, TopEdge.
  89.  */
  90. {
  91.    Point                     pos;
  92.    struct GraphicObjectClass *class;
  93.  
  94.    pos = Point_ZeroZero;
  95.  
  96.    if( class = (struct GraphicObjectClass *)self->isa )
  97.    {
  98.       if( class->SetLocation )
  99.          pos = (*class->SetLocation)( self, LeftEdge, TopEdge );
  100.    }
  101.    return pos;
  102. }
  103.  
  104.  
  105. Point Size( GraphicObject *self )
  106. /* Returns the Width, Height of 'self'.
  107.  */
  108. {
  109.    Point                      size;
  110.    struct GraphicObjectClass *class;
  111.  
  112.    size = Point_ZeroZero;
  113.  
  114.    if( class = (struct GraphicObjectClass *)self->isa )
  115.    {
  116.       if( class->Size )
  117.          size = (*class->Size)( self );
  118.    }
  119.    return size;
  120. }
  121.  
  122.  
  123. Point AskSize( GraphicObject *self,
  124.                PIXELS         Width,
  125.                PIXELS         Height )
  126. /* Given a (Width, Height), returns the nearest (Width, Height)
  127.  * that 'self' modify itself to be.  Does NOT actually change
  128.  * the dimensions of 'self'.
  129.  */
  130. {
  131.    Point                       size;
  132.    struct GraphicObjectClass *class;
  133.  
  134.    size = Point_ZeroZero;
  135.  
  136.    if( class = (struct GraphicObjectClass *)self->isa )
  137.    {
  138.       if( class->AskSize )
  139.          size = (*class->AskSize)( self, Width, Height );
  140.    }
  141.    return size;
  142. }
  143.  
  144.  
  145. Point SetSize( GraphicObject *self,
  146.                 PIXELS         Width,
  147.                 PIXELS         Height )
  148. /* Sets 'self's size to be as near (Width, Height) as possible,
  149.  * returns the actual (Width, Height).
  150.  */
  151. {
  152.    Point                       size;
  153.    struct GraphicObjectClass *class;
  154.  
  155.    size = Point_ZeroZero;
  156.  
  157.    if( class = (struct GraphicObjectClass *)self->isa )
  158.    {
  159.       if( class->SetSize )
  160.          size = (*class->SetSize)( self, Width, Height );
  161.    }
  162.    return size;
  163. }
  164.  
  165.  
  166. UWORD SizeFlags( GraphicObject *self )
  167. {
  168.    struct GraphicObjectClass *class;
  169.    UWORD flags;
  170.  
  171.    if( class = (struct GraphicObjectClass *)self->isa )
  172.    {
  173.       if( class->SizeFlags )
  174.          flags = (*class->SizeFlags)( self );
  175.    }
  176.    return flags;
  177. }
  178.  
  179.  
  180.  
  181. void Render( GraphicObject *self,
  182.              RastPort      *RPort )
  183. {
  184.    struct GraphicObjectClass *class;
  185.  
  186.  
  187.    if( class = (struct GraphicObjectClass *)self->isa )
  188.    {
  189.       if (class->Render)
  190.          (*class->Render)( self, RPort );
  191.    }
  192. }
  193.  
  194.  
  195.  
  196. UWORD GraphicObject_SizeFlagsNone( GraphicObject *self )
  197. {
  198.    return 0;
  199. }
  200.  
  201. UWORD GraphicObject_SizeFlagsX( GraphicObject *self )
  202. {
  203.    return OBJSIZE_X;
  204. }
  205.  
  206. UWORD GraphicObject_SizeFlagsY( GraphicObject *self )
  207. {
  208.    return OBJSIZE_Y;
  209. }
  210.  
  211. UWORD GraphicObject_SizeFlagsAll( GraphicObject *self )
  212. {
  213.    return OBJSIZE_X | OBJSIZE_Y;
  214. }
  215.  
  216.  
  217. BOOL SetTitle( GraphicObject *self, char *title )
  218. {
  219.    struct GraphicObjectClass *class;
  220.  
  221.  
  222.    if( class = (struct GraphicObjectClass *)self->isa )
  223.    {
  224.       if( class->SetTitle )
  225.          return (*class->SetTitle)( self, title );
  226.       else
  227.          return FALSE;
  228.    }
  229.    return FALSE;
  230.  
  231. }
  232.  
  233.  
  234. char *Title( GraphicObject *self )
  235. /* Returns a pointer to the title of an object, or NULL if none. */
  236. {
  237.    struct GraphicObjectClass *class;
  238.  
  239.  
  240.    if( class = (struct GraphicObjectClass *)self->isa )
  241.    {
  242.       if( class->Title )
  243.          return (*class->Title)( self );
  244.       else
  245.          return NULL;
  246.    }
  247.    return NULL;
  248. }
  249.  
  250. AlignInfo go_DefaultAlignment = { 0xFF, 0, 0 };
  251.  
  252. AlignInfo *TextAlignment( GraphicObject *self )
  253. {
  254.    struct GraphicObjectClass *class;
  255.  
  256.    if( class = (struct GraphicObjectClass *)self->isa )
  257.    {
  258.       if( class->TextAlignment )
  259.          return (*class->TextAlignment)(self);
  260.       else
  261.          return &go_DefaultAlignment;
  262.    }
  263.    else
  264.       return NULL;
  265. }
  266.  
  267. BOOL SetTextAlignment( GraphicObject *self,
  268.                             UBYTE         Flags,
  269.                             BYTE          Xpad,
  270.                             BYTE          Ypad )
  271. {
  272.    struct GraphicObjectClass *class;
  273.  
  274.    if( class = (struct GraphicObjectClass *)self->isa )
  275.    {
  276.       if( class->SetTextAlignment )
  277.          return (*class->SetTextAlignment)(self, Flags, Xpad, Ypad);
  278.       else
  279.          return FALSE;
  280.    }
  281.    else
  282.       return FALSE;
  283. }
  284.  
  285. /* additions for default font information */
  286. TextAttr go_DefaultFont =
  287.  { "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  288.  
  289. TextAttr *DefaultFont( GraphicObject *self )
  290. {
  291.    struct GraphicObjectClass *class;
  292.  
  293.    if( class = (struct GraphicObjectClass *)self->isa )
  294.    {
  295.       if( class->DefaultFont )
  296.          return (*class->DefaultFont)(self);
  297.       else
  298.          return &go_DefaultFont;  /* Topaz80 */
  299.    }
  300.    else
  301.       return NULL;
  302. }
  303.  
  304. BOOL SetDefaultFont( GraphicObject *self, TextAttr *default_font )
  305. {
  306.    struct GraphicObjectClass *class;
  307.  
  308.    if( class = (struct GraphicObjectClass *)self->isa )
  309.    {
  310.       if (class->SetDefaultFont)
  311.          return (*class->SetDefaultFont)( self, default_font );
  312.       else
  313.          return FALSE;
  314.    }
  315.    return FALSE;
  316. }
  317.  
  318. void GraphicObject_Init( GraphicObject *self )
  319. {
  320.    PObject_Init( (PObject *)self );
  321.  
  322.    self->isa = GraphicObjectClass();
  323.    self->Next = NULL;
  324. }
  325.